package com.cdatos.golGana.util;

import org.springframework.context.support.ClassPathXmlApplicationContext;

/**
 * Contains a unique instance of Spring context. 
 * Should be the only way for accessing Spring context.
 * @author sebastian.verrone
 */
public class ApplicationFactory {

	private static ApplicationFactory applicationFactory = new ApplicationFactory();
	private ClassPathXmlApplicationContext context = null;

    private ApplicationFactory() {
		init();
    }

	private void init() {
		context = new ClassPathXmlApplicationContext(getContextDefinition());
	}

	protected String[] getContextDefinition() {
		return new String[] { "application-context.xml",
				"database-context.xml", "service-definition.xml",
				"aop-definition.xml", "service-transaction.xml" };
	}

	public static Object getBean(final String beanName) {
		return applicationFactory.context.getBean(beanName);
	}
	
	public static ApplicationFactory getInstance() {
		return applicationFactory;
	}
}
